<?php

namespace App\Admin\Controllers;

use App\Models\PayMethod;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
use Illuminate\Http\Request;
use Illuminate\Support\MessageBag;

class PayMethodController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header(trans('admin.menu_titles.pay_method'))
//            ->description('description')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header(trans('admin.menu_titles.pay_method'))
//            ->description('description')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header(trans('admin.menu_titles.pay_method'))
//            ->description('description')
            ->body($this->editForm()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header(trans('admin.menu_titles.pay_method'))
//            ->description('description')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new PayMethod);

        $grid->id('Id');
        $grid->name(trans('admin.name'));
        $grid->icon(trans('admin.icon'));
        $grid->spell(trans('admin.spell'));
        $grid->is_show(trans('admin.show'))->switch();
        $grid->created_at(trans('admin.created_at'));
        $grid->updated_at(trans('admin.updated_at'));
        $grid->actions(function ($action) {
//            $action->disableEdit();
            $action->disableView();
            $action->disableDelete();
        });
        $grid->disableExport();
        $grid->disableRowSelector();

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(PayMethod::findOrFail($id));

        $show->id('Id');
        $show->name(trans('admin.name'));
        $show->icon(trans('admin.icon'));
        $show->spell(trans('admin.spell'));
        $show->created_at(trans('admin.created_at'));
        $show->updated_at(trans('admin.updated_at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new PayMethod);

        $form->text('name', trans('admin.name'))->rules('required')->setLabelClass(['required']);
        $form->text('spell', trans('admin.spell'))->help(trans('admin.sys_messages.pay_method_help'))->rules('required')->setLabelClass(['required']);
        $form->image('icon', trans('admin.icon'));
        $form->switch('is_show', trans('admin.show'));
        $form->disableEditingCheck();

        $form->disableCreatingCheck();

        $form->disableViewCheck();

        $form->tools(function (Form\Tools $tools) {
            $tools->disableDelete();
            $tools->disableView();
//            $tools->disableList();
        });
        return $form;
    }

    protected function editForm()
    {
        $form = new Form(new PayMethod);

        $form->text('name', trans('admin.name'))->rules('required')->setLabelClass(['required']);
        $form->display('spell', trans('admin.spell'));
        $form->image('icon', trans('admin.icon'));
        $form->disableEditingCheck();

        $form->disableCreatingCheck();

        $form->disableViewCheck();

        $form->tools(function (Form\Tools $tools) {
            $tools->disableDelete();
            $tools->disableView();
//            $tools->disableList();
        });
        return $form;
    }
}
